package com.etoak.controller;

import com.etoak.common.utils.DateUtils;
import com.etoak.common.utils.uuid.IdUtils;
import com.etoak.entity.DesignGuide;
import com.etoak.entity.TypicalProblem;
import com.etoak.service.IDesignGuideService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设计指导库 Controller
 *
 * @Author zhixuebin
 * @Date 2022/5/18
 */
@RestController
@RequestMapping("/goertek/designGuide")
public class DesignGuideController extends BaseController {

    @Autowired
    IDesignGuideService designGuideService;

    /**
     * 添加设计指导记录
     * @param designGuide
     * @return
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody DesignGuide designGuide){

        //设置主键
        String id = IdUtils.simpleUUID();
        designGuide.setId(id);

        designGuide.setCreateTime(DateUtils.getNowDate());
        designGuide.setDelStatus("0");

        int i = designGuideService.add(designGuide);
        if(i > 0){
            return AjaxResult.success("添加成功");
        }
        return AjaxResult.error("添加失败");
    }

    /**
     * 获取典型问题列表（分页）
     * @param pageNo
     * @param pageSize
     * @param designGuide
     * @return
     */
    @GetMapping("/getList")
    public PageInfo getList(@RequestParam(value = "pageNo",defaultValue = "1")Integer pageNo,
                            @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize,
                            DesignGuide designGuide){
        PageHelper.startPage(pageNo,pageSize);
        List<DesignGuide> designGuideList = designGuideService.getList(designGuide);
        PageInfo info = new PageInfo(designGuideList);
        return info;
    }

    /**
     * 根据id展示详情
     * @param id
     * @return
     */
    @GetMapping("/getById")
    public AjaxResult getById(@RequestParam("id") String id){
        DesignGuide item = designGuideService.getById(id);
        if(item != null){
            return AjaxResult.success(item);
        }else{
            return AjaxResult.error("无此记录");
        }
    }

}
